import request from '@/utils/request'

/**
 * 公告管理API接口
 */

// 分页查询公告列表
export function getAnnouncementPage(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/announcements/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 根据ID查询公告详情
export function getAnnouncementById(announcementId) {
  return request({
    url: `/api/announcements/${announcementId}`,
    method: 'get'
  })
}

// 获取最新公告列表
export function getAnnouncements(params) {
  return request({
    url: '/api/announcements/latest',
    method: 'get',
    params
  })
}

// 新增公告
export function addAnnouncement(announcementData) {
  return request({
    url: '/api/announcements',
    method: 'post',
    data: announcementData
  })
}

// 更新公告信息
export function updateAnnouncement(announcementData) {
  return request({
    url: '/api/announcements',
    method: 'put',
    data: announcementData
  })
}

// 删除公告
export function deleteAnnouncement(announcementId) {
  return request({
    url: `/api/announcements/${announcementId}`,
    method: 'delete'
  })
}

// 批量删除公告
export function batchDeleteAnnouncements(announcementIds) {
  return request({
    url: '/api/announcements/batch',
    method: 'delete',
    data: announcementIds
  })
}

// 发布公告
export function publishAnnouncement(announcementId) {
  return request({
    url: `/api/announcements/${announcementId}/publish`,
    method: 'put'
  })
}

// 取消发布公告
export function unpublishAnnouncement(announcementId) {
  return request({
    url: `/api/announcements/${announcementId}/unpublish`,
    method: 'put'
  })
}

// 置顶公告
export function topAnnouncement(announcementId) {
  return request({
    url: `/api/announcements/${announcementId}/top`,
    method: 'put'
  })
}

// 取消置顶公告
export function untopAnnouncement(announcementId) {
  return request({
    url: `/api/announcements/${announcementId}/untop`,
    method: 'put'
  })
}

// 获取公告类型列表
export function getAnnouncementTypes() {
  return request({
    url: '/api/announcements/types',
    method: 'get'
  })
}

// 获取公告状态列表
export function getAnnouncementStatuses() {
  return request({
    url: '/api/announcements/statuses',
    method: 'get'
  })
}

// 统计公告数量
export function countAnnouncements() {
  return request({
    url: '/api/announcements/count',
    method: 'get'
  })
}

// 根据状态统计公告数量
export function countAnnouncementsByStatus(status) {
  return request({
    url: '/api/announcements/count-by-status',
    method: 'get',
    params: { status }
  })
}